import requests


class TestTpshopLogin:
    # 登录成功
    def test_login_success(self):
        session = requests.session()
        resp_v = session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        url2 = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login&t=0.9112008475406435"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"username": "17788888888", "password": "123456", "verify_code": "8888"}
        resp_login = session.post(url=url2, headers=header, data=body)
        print(resp_login.json())

        # 断言
        assert 200 == resp_login.status_code
        assert 1 == resp_login.json().get('status')
        assert '登陆成功' == resp_login.json().get('msg')

    # 用户名错误
    def test_username_error(self):
        session = requests.session()
        resp_v = session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        url2 = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login&t=0.9112008475406435"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"username": "17788888883", "password": "123456", "verify_code": "8888"}
        resp_login = session.post(url=url2, headers=header, data=body)
        print(resp_login.json())

        # 断言
        assert 200 == resp_login.status_code
        assert -1 == resp_login.json().get('status')
        assert '账号不存在!' == resp_login.json().get('msg')

    # 密码错误
    def test_password_error(self):
        session = requests.session()
        resp_v = session.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        url2 = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login&t=0.9112008475406435"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"username": "17788888888", "password": "123450", "verify_code": "8888"}
        resp_login = session.post(url=url2, headers=header, data=body)
        print(resp_login.json())

        # 断言
        assert 200 == resp_login.status_code
        assert -2 == resp_login.json().get('status')
        assert '密码错误!' == resp_login.json().get('msg')

